<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body>
	<form id="form1" method="post">
        <div style="padding-left:30px;padding-bottom:10px;">
            <table style="width:80%;padding-top:10px;" cellspacing="0" cellpadding="8">
            	<tr>
            		<td style="width:80px;">用户名：</td>
            		<td><input class="mini-textbox" readOnly="true" style="width:180px;" name="name"/></td>
            	</tr>
            	<tr>
               		<td style="width:80px;">部门：</td>
               		<td><input name="id" class="mini-hidden" />
               			<input class="mini-textbox asLabel" readOnly="true" name="deptName" style="width: 180px;"/>
               		</td>
               	</tr>
               	<tr>
               		<td style="width:80px;">组：</td>
               		<td>
               			<input class="mini-textbox asLabel" name="groupName" readOnly="true" style="width: 180px;"/>
               		</td>
                </tr>
                <tr>
                    <td style="width:80px;">性别：</td>
                    <td>
                    	<input id="combo1" name="gender" class="mini-combobox" style="width:180px;" textField="keyValue" valueField="keyName" emptyText="请选择..."
				        		url="dictionary_key_val_view.do?typeName=GENDER_TYPE" required="true" allowInput="false" showNullItem="true" nullItemText="请选择..."/>
                    </td>
                </tr>
                <tr>
                	<td style="width:80px;">身份证号：</td>
                	<td><input name="idCardNum" class="mini-textbox" onvalidation="onIDCardsValidation" style="width:180px;" /></td>
                </tr>
                <tr>
                    <td style="width:80px;">入职时间：</td>
                    <td><input id="date1" name="entryTime" class="mini-datepicker" style="width:180px;" required="true" allowInput="false"/></td>
                </tr>
                <tr>
                	<td style="width:80px;">合同编号：</td>
                	<td><input name="contractNum" class="mini-textbox" vtype="maxLength:50" style="width:180px;" required="true" /></td>
                </tr>
                <tr>
		           	<td style="width: 80px;">档案文件：</td>
		           	<td><input id="file_upload" name="file_upload" type="file"/></td>
		        </tr>
            </table>
        	<input id="file_url" name="archivesUrl" emptyText="上传文件路径..." class="mini-textbox" readOnly="true" style="width:340px;"/>
        </div>
        <input id="file_size" name="fileSize" class="mini-hidden" />
        <input id="file_type" name="fileType" class="mini-hidden" />
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>
</body>
</html>

<script type="text/javascript">
	mini.parse();
	
	var form = new mini.Form("form1");
	
	//保存数据
	function SaveData() {
	    form.validate();
	    var o = form.getData(true);
	    if (form.isValid() == false) return;
		$.ajax({
	        url: "archival_save_edit.do",
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误！");
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
		 });
	}
	
    function GetData() {
        var o = form.getData();
        return o;
    }
    
    function SetData(data) {
		data = mini.clone(data);
 		form.setData(data.row);
    }
    
    function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
    
    function onOk(e) {
        SaveData();
    }
    
    function onCancel(e) {
        CloseWindow("cancel");
    }
    
    function onIDCardsValidation(e) {
        if (e.isValid) {
            var pattern = /\d*/;
            if (e.value.length > 18|| e.value.length < 15 || pattern.test(e.value) == false) {
                e.errorText = "必须输入15~18位数字";
                e.isValid = false;
            }
        }
    }
    
    $(function(){
    	setTimeout(function(){
	    	$('#file_upload').uploadify({
	    		'auto':true,
	    		'swf':'scripts/uploadify/uploadify.swf',
	    		'uploader':'archival_file_upload.do;jsessionid=<%=session.getId()%>',
	    		'buttonText':'选择文件',
	    		'queueSizeLimit':1,
	    		'onSWFReady':function(){
	    			var fileType = mini.getbyName("fileType").getValue();
	    			var fileSize = mini.getbyName("fileSize").getValue();
	    			$('#file_upload').uploadify('settings','fileTypeExts',fileType);
	    			$('#file_upload').uploadify('settings','fileSizeLimit',fileSize+'MB');
	    		},
	    		'onUploadSuccess':function(file, data, response){
	    			data = eval('(' + data + ')');
	    			if(data.success == "true"){
	    				mini.get("file_url").setValue(data.archivesUrl);
	    			}else{
	    				mini.alert("文件上传失败");
	    			}
	    		}
	    	});
    	}, 150);
    });
</script>